import { Result, deleteRequest, get, post } from "../base";

/**
 * 新增
 * @param data .
 * @returns .
 */
export function uploadFile<T>(data: any): Promise<Result<T>> {
  return post("/sci/file/upload", data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}
/**
 * 预览文件
 * @param query .
 * @returns .
 */
export function previewFile<T>(path: any): Promise<Result<T>> {
  return get(
    `sci/file/preview?path=${encodeURIComponent(path)}`,
    {},
    {
      responseType: "arraybuffer"
    }
  );
}
export function downloadFile<T>(data: any): Promise<Result<T>> {
  return post("/sci/file/download", data, {
    responseType: "arraybuffer"
  });
}

export function exportData<T>(data: any): Promise<Result<T>> {
  return post("/sci/file/exportData", data, { responseType: "blob" });
}

export function deleteFile(path: string) {
  return deleteRequest(`/sci/file/delete`, {}, path);
}
